<!--
* @description  : 案件-案件当事人-当事人列表
* @descriptionDetail: 案件-案件当事人（法人/其他组织，输入统一社会信用代码(营业执照) 展示选择当事人列表的按钮）
* @copyright    : 浙江烟草
* @author       : dw
* @create       : 2022-10-09 22:21:21
-->
<template>
	<view class="page">
		<!-- #ifdef H5-ONLY -->
		<theme-navbar
		 :is-white="false"
		 :title="navTitle"
		 :custom-back="goBack"
		 style="z-index: 99999"
		 >
			<view class="nav-right-icon">
				<view @tap="handlerSure">
					确定
				</view>
			</view>
		</theme-navbar>
		<!-- #endif -->
		<!-- #ifdef H5-WECHAT || H5-EMP -->
		 <fab-button :content="fContent" @fabtrigger="fabtrigger" />
		<!-- #endif -->
		<me-table
		 :i="0"
		 :top="2"
		 :index="0"
		 :load-data="loadData"
		 :init-load="false"
		  ref="mescrollItem0">
			<template #default="d">
				<view class="card">
					<u-row @tap="handlerSelectItem(d.data)">
						<u-col span="10">
							<party-list-item :itemInfo="d.data"></party-list-item>
						</u-col>
						<u-col span="2" style="text-align:right;">
							<u-icon
							 name="checkbox-mark"
							  color="#2979ff"
							   size="38"
							    style="margin-right: 10px;"
							     v-if="selectedUids.includes(d.data.custUuid)"
							     ></u-icon>
						</u-col>
					</u-row>
				</view>
			</template>
		</me-table>
	</view>
</template>

<script>
	import MeTable from '@/components/me-table.vue';
	import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
	import partyListItem from './partyListItem';
	import caseService from "@/service/case/case.service";
	import fabButton from '@/components/uni-fab.vue';
	import {
		isDD,
	} from "@/common/util";
	export default {
		components: {
			MeTable,
			fabButton,
			partyListItem,
		},
		mixins: [MescrollMoreMixin, ],
		data() {
			return {
				keyword: "",
				selectedUids: [], // 选中项的ids
				selectedItems: [], // 选中项
				objInfo: {},
				busiLicNo: undefined,
				fContent: [{
					iconPath: require('@/static/confirm.png'),
					selectedIconPath: require('@/static/confirm.png'),
					text: '确定',
					active: false,
				}],
			};
		},
		onLoad(opt) {
			this.busiLicNo = opt.busiLicNo;
		},
		methods: {
			setRightBtns() {
				// #ifdef H5-DINGDING
				this.$deviceApi.setRight("确定", () => {
					this.handlerSure();
					this.setRightBtns();
				}, true, true);
				// #endif
			},
			fabtrigger(btn) {
				if (btn.index == 0) {
					this.handlerSure()
				}
			},
			handlerSearch() {
				this.$refs['mescrollItem0'].refresh();
			},
			// 选中
			handlerSelectItem(item) {
				this.selectedUids = [item.custUuid, ];
				this.selectedItems = [item, ];
			},
			loadData(page) {
				let param = {
					page: page.num,
					limit: page.size,
					partyType: '02',
					busiLicNo: this.busiLicNo,
				}
				return new Promise((resolve, reject) => {
					caseService.getPartyInfoByBusLicNo(param).then(res => {
						if (res.success) {
							resolve({
								count: res.count,
								data: res.data,
							});
						} else {
							this.$u.toast(res.msg);
							resolve({
								count: 0,
								data: [],
							});
						}
					}).catch(e => {
						this.$u.toast('请求失败:' + e);
						resolve({
							count: 0,
							data: [],
						});
					});
				})
			},
			updateBackState() {
				this.$refs['mescrollItem0'].refresh();
			},
			// 确定
			handlerSure() {
				let self = this;
				if (this.selectedItems.length == 0) {
					this.$u.toast("请选择当事人");
					return;
				}
				// TODO 直接跳转到 考核计划检查页面
				this.backPrev({
					paramKey: 'refresh',
					param: this.selectedItems,
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	@import "@/style/common/rightMenu.scss";

	.page {
		padding: 0;
	}

	.u-page {
		padding-bottom: 100rpx;
	}

	.nolicence-search-lay {
		background-color: #fff;
		position: fixed;
		// #ifndef H5-DINGDING
		top: 44px;
		// #endif
		// #ifdef H5-DINGDING
		top: 0px;
		// #endif
		z-index: 999;
		width: 100%;
		overflow: hidden;
		padding: $cm-search-padding-row $cm-search-padding-column;
	}

	.sticky-header {
		background-color: #fff;
		position: fixed;
		/* #ifdef H5-DINGDING  */
		top: 0px;
		/* #endif */
		/* #ifndef H5-DINGDING  */
		top: 44px;
		/* #endif */
		width: 100%;
		margin: auto;
		padding-left: 2.5%;
		padding-right: 2.5%;
		line-height: 40px;
		height: 40px;
		z-index: 999;
		padding: $cm-search-padding-row $cm-search-padding-column;
	}
</style>
